package SceneTrigger

import (
	. "misc/Clojure"
	. "misc/Clojure/parse"
	"time"
)

func defineTriggerVarAction() {
	MainContext.Define("vector-s", NativeFunction{MyFunction: _vector_s})
	MainContext.Define("def-timer", NativeFunction{MyFunction: _def_timer})
}

func _vector_s(args []Node, context *Context) Node {
	args = EvalArgs(args, context)
	vectorNumber := args[0].(*NumberNode).Val.(int)
	vecNode := &VectorNode{}
	vecNode.Nodes = make([]Node, vectorNumber)
	for i := 0; i < vectorNumber; i++ {
		vecNode.Nodes[i] = args[1]
	}
	return nil
}

func _def_timer(args []Node, context *Context) Node {
	args = EvalArgs(args, context)
	durationTime := args[0].(*NumberNode).Val.(float64)
	newTimer := NewTriggerTimer(durationTime)
	return &ObjectNode{Val: newTimer}
}

//计时器
type TriggerTimer struct {
	StartTime    time.Time
	DurationTime float64
}

func NewTriggerTimer(durationTime float64) *TriggerTimer {
	retTimer := &TriggerTimer{
		StartTime:    time.Now(),
		DurationTime: durationTime,
	}
	return retTimer
}
